package com.zrz.util;

import com.zrz.wechart.*;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

/**
 * 类名: MenuManager </br>
 * 包名： com.souvc.weixin.main
 * 描述:菜单管理器类 </br>
 * 发布版本：V1.0  </br>
 */
public class MenuManager {

    public static int addMenu(String appId,String appSecret,String url) {

        // 调用接口获取access_token
        WeixinOauth2Token at = WeixinUtil.getAccessToken(appId, appSecret);

        if (null != at) {
            // 调用接口创建菜单
            int result = WeixinUtil.createMenu(getMenu(appId,appSecret,url), at.getAccessToken());

            // 判断菜单创建结果
            if (0 == result)
                LogUtils.info("菜单创建成功！");
            else
                LogUtils.info("菜单创建失败!");
            return result;
        }
        return 1;
    }


    /**
     * 组装菜单数据
     *
     * @return
     */
    private static Menu getMenu(String appId,String secret,String url) {
        ComplexButton mainBtn1 = new ComplexButton();
        mainBtn1.setName("领酒");
        CommonButton indexBtn = new CommonButton();
        //一级下有1个子菜单
        indexBtn.setName("领酒地址");
        indexBtn.setType("view");
        indexBtn.setKey("index");
        indexBtn.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+url+"/oauth/index&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect");

        CommonButton reciveBtn = new CommonButton();
        //一级下有1个子菜单
//        reciveBtn.setName("商户入口");
//        reciveBtn.setType("view");
//        reciveBtn.setKey("recive");
//        reciveBtn.setUrl(url+"/admin/toLoginPage");
        reciveBtn.setName("扫码领酒");
        reciveBtn.setType("scancode_push");
        reciveBtn.setKey("saoyisao");
//        reciveBtn.setUrl(url+"/admin/toLoginPage");
//        mainBtn1.setSub_button(new CommonButton[]{reciveBtn,indexBtn});
        ComplexButton mainBtn2 = new ComplexButton();
        mainBtn2.setName("会员权益");
        CommonButton btn20 = new CommonButton();
        //一级下有1个子菜单
        btn20.setName("推广赠酒");
        btn20.setType("click");
        btn20.setKey("extension");
//        btn20.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+url+"/oauth/extension&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect");
        CommonButton btn21 = new CommonButton();
        //一级下有1个子菜单
        btn21.setName("加入会员");
        btn21.setType("view");
        btn21.setKey("join");
        btn21.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri=http://wechat.uwetech.cn/oauth/addVip&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect");
        CommonButton btn22 = new CommonButton();
        //一级下有1个子菜单
        btn22.setName("会员资料");
        btn22.setType("view");
        btn22.setKey("personInfo");
        btn22.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+url+"/oauth/mine&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect");
        CommonButton btn33 = new CommonButton();
        btn33.setName("成为加盟商");
        btn33.setType("view");
        btn33.setKey("jiamengshang");
//        btn33.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+url+"/oauth/addBusiness&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect");
        btn33.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri=http://wechat.uwetech.cn/oauth/addBusiness&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect");

        mainBtn2.setSub_button(new CommonButton[]{btn21,btn20,  btn22,reciveBtn,btn33});
//        CommonButton ShoppingMallBtn = new CommonButton();
//        //一级下有1个子菜单
//        ShoppingMallBtn.setName("会员商城");
//        ShoppingMallBtn.setType("click");
//        ShoppingMallBtn.setKey("shoppingMall");
//        ShoppingMallBtn.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+url+"/oauth/index&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect");
//        ShoppingMallBtn.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri=+"+url+"/oauth/member&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect");
        SmallButton ShoppingMallBtn = new SmallButton();
        //一级下有1个子菜单
        ShoppingMallBtn.setName("会员商城");
        ShoppingMallBtn.setType("miniprogram");
        ShoppingMallBtn.setKey("shoppingMall");
        ShoppingMallBtn.setUrl("http://mp.weixin.qq.com");
        ShoppingMallBtn.setAppid("wx2394972264f2983c");
        ShoppingMallBtn.setPagepath("pages/index/index");

        Menu menu = new Menu();
        menu.setButton(new Button[]{indexBtn, mainBtn2, ShoppingMallBtn});

        return menu;
    }


    public static  void main(String arg[]){
        Map map=new HashMap();
        map.put(null,"11");
//        Map map1=new Hashtable();
//        map1.put(null,22);
        System.out.println(map.get(null));
//        System.out.println(map1.get(null));
    }
}
